package br.com.hotel68.view.gui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import br.com.hotel68.Hotel68BusinessFacade;
import br.com.hotel68.model.Hosting;

public class AddAmount extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JFormattedTextField formattedTextField;
	private Hosting hosting;
	private Hotel68BusinessFacade facade;
	

	
	/**
	 * Create the dialog.
	 */
	public AddAmount(Hosting _hosting, Hotel68BusinessFacade _facade) {
		this.facade = _facade;
		this.hosting = _hosting;
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		this.setVisible(true);
		setBounds(100, 100, 450, 152);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			formattedTextField = new JFormattedTextField();
			formattedTextField.setBounds(224, 11, 200, 20);
			contentPanel.add(formattedTextField);
		}
		
		JLabel lblNewLabel = new JLabel("Valor a adicionar");
		lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblNewLabel.setBounds(41, 14, 127, 17);
		contentPanel.add(lblNewLabel);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						String text = formattedTextField.getText();
						//TODO: TRABALHAR AS EXCECOES
						//TODO: CRIAR CAIXA PARA DESCRICAO E ADICIONAR ABAIXO
						
						facade.addAmount(hosting, Double.parseDouble(text),"blabalb");
						
						
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
}
